<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>权限</title>
<link rel="stylesheet" type="text/css"
	href="/Goktech-Bank-System/easyui/demo/demo.css">
<script type="text/javascript"
	src="/Goktech-Bank-System/common/lib/jquery-1.8.3.min.js"></script>
<!-- 载入easyui样式及图标样式  注意该一下路径-->
<link rel="stylesheet" type="text/css"
	href="/Goktech-Bank-System/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="/Goktech-Bank-System/easyui/themes/icon.css">
<!-- 载入jquery支持文件（必须写在其他js文件前）、easyui支持文件、easyui中文支持文件 -->
<script type="text/javascript"
	src="/Goktech-Bank-System/easyui/jquery.min.js"></script>
<script type="text/javascript"
	src="/Goktech-Bank-System/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="/Goktech-Bank-System/easyui/locale/easyui-lang-zh_CN.js"></script>
<style>
.black_overlay {
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	background-color: black;
	z-index: 1001;
	-moz-opacity: 0.8;
	opacity: .80;
	filter: alpha(opacity = 80);
}

.white_content {
	display: none;
	position: absolute;
	top: 10%;
	left: 25%;
	width: 50%;
	height: 80%;
	border: 16px solid lightblue;
	background-color: white;
	z-index: 1002;
	overflow: auto;
}

.divmargin {
	margin: 20px 0px 10px 0px;
}
</style>
</head>

<body>
	<table id="dg" title="权限组管理" style="width: 100%;"
		data-options="singleSelect:true,pagination:true,url:'/Goktech-Bank-System/quanx/easyuiGetData',method:'get',toolbar:'#tb'">
		<thead>
			<tr>
				<th style="width:34%" data-options="field:'id',width:600">权限id</th>
				<th style="width:34%" data-options="field:'quanxmc',width:600">权限组名称</th>
				<th style="width:33%" data-options="field:'_operate',width:375,formatter:rowformater">操作</th>
			</tr>
		</thead>
	</table>
	
	<div id="tb">
		权限组名称 <input type="text" name="standard.minWeight" id="zt" /><a
			id="standardQueryBtn" href="javascript:void(0)"
			class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
	</div>

	<div id="fade" class="black_overlay"></div>
	<div id="MyDiv" class="white_content">
		<div class="divmargin">
			权限名 <INPUT id="quanxmc" class="textInput"
				style="height: 28px; width: 300PX" maxLength="150" size=30 type=text
				name="quanxmc"> <input id="quanxid" value="" type="hidden">
			<BR>
		</div>
		<ul id="tt" data-options="checkbox:true"></ul>
		<div id="fade" class="black_overlay"></div>
		<div style="text-align: center; cursor: default; height: 40px;"
			id="move">
			<button style="font-size: 16px;" onclick="getCheck()" id="sub">确定</button>
			<button style="font-size: 16px;" onclick="CloseDiv('MyDiv','fade')">关闭</button>
		</div>
	</div>

	<script type="text/javascript">
		//如果要显示选择框 需要在html空间上使用 data-options="checkbox:true"
		/* 		$(function () {
		 //使用esyui构造tree数据格式必须是json
		 $('#tt').tree({
		 method: "get",
		 url: "/Goktech-Bank-System/caid/getAll",
		 lines: true,
		 });
		 }) */
		 
		 $("#standardQueryBtn").click(function() {
	           //$("#dg") 获取easui的数据表格   datagrid("load" 重新加载表格 后面的几个数据是请求的参数
				$("#dg").datagrid("load", {
					"quanxmc" : $("#zt").val()
				});

			});

		function rowformater(value, row, index) {
 			return "<button onclick=delQuanx('"+row.id+"')>删除</button>"; 
		}
		
		function delQuanx(id){
			if (confirm("确认删除吗？") == true) {
				$.get("/Goktech-Bank-System/quanx/delQuanx",{"id":id},function(data){
					if (data.code == 1) {
						alert("删除成功")
					}else{
						alert("删除失败")
					}
					window.location.reload();
				});
			}else{
				return;
			}
			
		}

		function getCheck(a) {
			if (a == "add") {/* 添加 */
				link = '/Goktech-Bank-System/quanx/addQuanx';
			} else if (a == 'modify') {/* 修改 */
				link = '/Goktech-Bank-System/quanx/modifyQuanx';
			}
			var nodes = $('#tt').tree('getChecked');
			//获取子节点选中（但是没有全部选中） 的父节点
			var nodes2 = $('#tt').tree('getChecked', 'indeterminate');
			console.log(nodes);
			console.log(nodes2);
			var List = []
			var quanxData = {}
			$.each(nodes, function() {
				quanxData.id = this.id;
				quanxData.text = this.text;
				quanxData.checked = this.checked;
				List.push(quanxData);
				quanxData = {}
			})
			$.each(nodes2, function() {
				quanxData.id = this.id;
				quanxData.text = this.text;
				quanxData.checked = this.checked;
				List.push(quanxData);
				quanxData = {}
			})
			if ($("#quanxmc").val() == "") {
				alert("权限名不能为空");
				return;
			}
			var param = {
				"id" : $("#quanxid").val(),
				"quanxmc" : $("#quanxmc").val(),
				"cList" : List
			}

			console.log(param)

			$.ajax({
				// headers必须添加，否则会报415错误
				headers : {
					'Accept' : 'application/json',
					'Content-Type' : 'application/json'
				},
				type : 'POST',
				dataType : "json", //表示返回值类型，不必须
				data : JSON.stringify(param),
				url : link,
				success : function(data) {
					if (data.code == 1) {
						CloseDiv('MyDiv', 'fade');
						//从新加载页面
						window.location.reload()
					} else {
						alert("添加失败");
					}
				}

			});
		}

		//弹出隐藏层
		function ShowDiv(show_div, bg_div) {
			document.getElementById(show_div).style.display = 'block';
			document.getElementById(bg_div).style.display = 'block';
			var bgdiv = document.getElementById(bg_div);
			bgdiv.style.width = document.body.scrollWidth;
			// bgdiv.style.height = $(document).height();
			$("#" + bg_div).height($(document).height());
		};
		//关闭弹出层
		function CloseDiv(show_div, bg_div) {
			document.getElementById(show_div).style.display = 'none';
			document.getElementById(bg_div).style.display = 'none';
		};

		$(function() {
			var pager = $('#dg').datagrid().datagrid('getPager'); // get the pager of datagrid
			pager
					.pagination({
						buttons : [
								{
									iconCls : 'icon-search',
									handler : function() {
										alert('search');
									}
								},
								{
									iconCls : 'icon-add',
									handler : function() {
										//跳转到添加页面
										/* location.href = "quanx_add.html"; */
										$('#tt')
												.tree(
														{
															method : "get",
															url : "/Goktech-Bank-System/caid/getAll",
															lines : true,
														});
										ShowDiv('MyDiv', 'fade');
										$("#sub").attr("onclick",
												"getCheck('add')")
									}
								},
								{
									iconCls : 'icon-edit',
									handler : function() {
										//获取选中的那一行数据
										var row = $('#dg').datagrid(
												'getSelected');
										console.log(row);

										$('#tt')
												.tree(
														{
															method : "get",
															url : '/Goktech-Bank-System/quanx/getAllCaidAndUserRights?id='
																	+ row.id,
															lines : true,
														});
										$("#quanxid").attr("value", row.id);
										$("#sub").attr("onclick",
												"getCheck('modify')");
										$("#quanxmc").val(row.quanxmc);
										ShowDiv('MyDiv', 'fade');
									}
								} ]
					});
		})

		function getSelected() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.messager.alert('Info', row.itemid + ":" + row.productid + ":"
						+ row.attr1);
			}
		}
	</script>
</body>

</html>